package com.hjh.thymeleafdemo1.web.component;

import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * 器 配置自定义的区域信息解析器 LocaleResolver 。
 * 功能 ：当在 login.html 登录页面中点击底部的 " 中文 " 或 "English" 链接时，可以在链接上携带区
 域信息， @{toLogin(l='en_US')}
 */
public class MyLocaleResolver implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        String lan = request.getParameter("1");
        Locale locale = Locale.getDefault();
        if (lan != null && lan.length()>0){
            String[] split = lan.split("_");
            locale = new Locale(split[0],split[1]);
        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}
